package com.example.my.agiftthat.ui.home.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.my.agiftthat.R;
import com.example.my.agiftthat.config.Url;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by My on 2016/12/3.
 */

public class FragmentHome extends Fragment {
    private Context mContext = null;
    private TabLayout tabLayout_home;
    private ViewPager viewPager_home;
    private List<Fragment> mList = new ArrayList<>();
    private String[] mArrHomeTitles = null;
    private String[] url = {Url.HOME_SNP, Url.HOME_HT, Url.HOME_KJF, Url.HOME_MS, Url.HOME_SJY,
            Url.HOME_SBM, Url.HOME_STS, Url.HOME_SBB, Url.HOME_SJG, Url.HOME_CY, Url.HOME_WYF, Url.HOME_QP,
            Url.HOME_SM, Url.HOME_MMD};

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = getActivity();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_home, null);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        tabLayout_home = (TabLayout) view.findViewById(R.id.tabLayout_home);
        viewPager_home = (ViewPager) view.findViewById(R.id.viewpager_home);

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mArrHomeTitles = getResources().getStringArray(R.array.arrHomeTitles);
        SelectorFragment fragment = new SelectorFragment();
        mList.add(fragment);
        for (int i = 1; i < mArrHomeTitles.length; i++) {
            SendFragment fragment1 = new SendFragment();
            mList.add(fragment1);
        }
        TabHomeAdapter adapter = new TabHomeAdapter(getChildFragmentManager(), mList, mArrHomeTitles);
        viewPager_home.setAdapter(adapter);
        tabLayout_home.setupWithViewPager(viewPager_home);
    }
}
